__author__ = 'shawhen'

import re


def parse_opt_an(netstat_opt_an_output, platform="windows"):
    """
    解析netstat -an 的输出
    :note 暂只支持ipv4
    """
    if platform == "windows":
        win_netstat_opt_an_regex = re.compile(r"(TCP|UDP)\s+(\d+.\d+.\d+.\d+):(\d+)\s+(\d+.\d+.\d+.\d+){0,1}:{0,1}(\d+){0,1}\s{0,}(LISTENING|ESTABLISHED|TIME_WAIT|CLOSE_WAIT){0,1}")
        match_results = win_netstat_opt_an_regex.findall(netstat_opt_an_output)
        if match_results is not None:
            for match_result in match_results:
                pass
    else:
        raise NotImplementedError